package com.itheima.leetcode.od.c.binary;

import java.util.Scanner;

/**
 * <h3>最多购买宝石数目</h3>
 */
public class MaximumnumberOfGems {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] gems = new int[count];
        for (int i = 0; i < count; ++i) {
            gems[i] = in.nextInt();
        }
        int value = in.nextInt();

        int right = 0;
        int left = 0;
        int length = 0;
        int total_used = 0;

        while (right < count) {
            total_used += gems[right];
            while (value < total_used) {
                total_used -= gems[left];
                left += 1;
            }
            length = Math.max(right - left + 1, length);
            right += 1;
        }
        System.out.println(length);
    }
}